package team.common.utility;

import java.util.Map;
import java.util.List; 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.view.AbstractView;
import org.jdom.Document;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

import team.common.utility.MakeXml;

public class XmlView extends AbstractView {
	/**
	 * @param map -
	 *            Map with name Strings as keys and corresponding model objects
	 *            as values (Map can also be null in case of empty model)
	 * @param request -
	 *            current HTTP request
	 * @param response -
	 *            HTTP response we are building
	 */
	   
	@SuppressWarnings("unchecked")
	protected void renderMergedOutputModel(Map map, HttpServletRequest request,HttpServletResponse response) throws Exception 
	{
		List list =(List)  map.get("AJAX_MODEL");
		response.setHeader("Cache-Control", "no-cache");
		System.out.println(list);
		MakeXml xml= new MakeXml();
		Document document = (Document) xml.make(list);
		
		XMLOutputter outputter = new XMLOutputter();
		Format format = Format.getPrettyFormat();
		format.setEncoding("euc-kr");
		outputter.setFormat(format);
//		response.setContentType("application/xml");
		response.setContentType("application/xml;charset=euc-kr");
		outputter.output(document, response.getWriter());
//		outputter.output(document, System.out);
	}
}
